from pathlib import Path
path = Path('alice.txt')
try:
    contents = path.read_text(encoding='utf-8')
except FileNotFoundError:
    print("No such file or directory")
else:
    words = contents.split()
    num_words = len(words)
    print("There are {} words in total".format(num_words))